function myCompose(...args) {
  let fnLength = args.length;
  let fn = args;
  for (let i = 0; i < fnLength; i++) {
    if (typeof fn[i] !== "function") {
      throw new TypeError("error");
    }
  }

  const compose = function (...args2) {
    let x = 0;
    let result = fnLength ? fn[x].apply(this, args2) : "";
    while (++x < fnLength) {
      result = fn[x].call(this, result);
    }
    return result;
  };
  return compose;
}

function double(m) {
  return m * 2;
}

function square(n) {
  return n ** 2;
}

var newFn = myCompose(double, square);
console.log(newFn(10));
